﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WpfApp_Mvvm.Mvvm;

public class CalculateLogic
{
    public CalculateDataModel CalculateDataModel { get; set; }
    public MvvmCommand CalculateCommand { get; set; }
    public MvvmCommand CheckChommand { get; set; }

    public CalculateLogic()
    {
        CalculateDataModel = new CalculateDataModel();
        CalculateDataModel.PropertyChanged += (sender, e) =>
        {
            if (new string[] { "Value1", "Value2" }.Contains(e.PropertyName))
            {
                CalculateCommand?.ResetCanExecute();
            }
        };
        CalculateCommand = new MvvmCommand(DoCalculate, DoCheck);
        CheckChommand = new MvvmCommand(HandelCheck);
    }


    public void DoCalculate()
    {
        CalculateDataModel.Result = CalculateDataModel.Value1 + CalculateDataModel.Value2;
    }

    public bool DoCheck()
    {
        return CalculateDataModel.Value1 > 0 && CalculateDataModel.Value2 > 0;
    }

    public void HandelCheck()
    {
        CalculateCommand.ResetCanExecute();
    }
}
